import 'dart:io';

import 'package:PollOnLine/utils/logger_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

///
/// @Description: dart类作用描述
/// @Author: 下雨了
/// @CreateDate: 2023-12-25 14:38
/// @UpdateUser: 更新者
/// @UpdateDate:  2023-12-25 14:38
/// @UpdateRemark: 更新说明
/// @Version: 1.0
///

/// Pushes a widget to a new route.
Future push(context, widget) {
  return Navigator.of(context).push(
    MaterialPageRoute(
      builder: (BuildContext context) {
        return widget;
      },
    ),
  );
}

/// true设置为横屏 false设置为竖屏
void setScreenLandscape(bool b) {
  if (b) {
    // 强制横屏
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeLeft,
      DeviceOrientation.landscapeRight,
    ]);
    // OrientationPlugin.forceOrientation(DeviceOrientation.landscapeLeft);
  } else {
    // 强制竖屏
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown,
    ]);
    // OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp);
  }
}

/// 判断是否为 iPad
bool isPad(BuildContext context) {
  double width = MediaQuery.of(context).size.width;
  double height = MediaQuery.of(context).size.height;
  bool isLandscape = width > height;
  // bool b = (Platform.isIOS || Platform.isAndroid) && (width > 900 || (isLandscape && height > 600));
  bool b = (Platform.isIOS || Platform.isAndroid) && MediaQuery.of(context).size.shortestSide > 600;
  kLog.i("width : $width, height ： $height ---是否为 ipad ： $b");
  return b;
}
